package top.wangjiu.java.jvm.constantinfo.refrence;

import top.wangjiu.java.jvm.constantinfo.ConstantPoolInfo;
import top.wangjiu.java.jvm.constantinfo.SymbolicReferenceConstantPoolInfo;

/**
 * @ClassName ClassInfo
 * @Description TODO
 * @Author wangjiu
 * @Date 2022/1/14 11:56 上午
 */
public class ClassCPInfo extends SymbolicReferenceConstantPoolInfo {

    public final static short TAG = 7;
    public final static short INFO_LENGTH = 2;

    private final short index;

    private final short nameIndex;


    public ClassCPInfo(byte[] bytes, short index){
        this.index = index;
        this.nameIndex = (short)(bytes[0]<<8 | bytes[1]);
    }

    @Override
    public short tag() {
        return TAG;
    }

    @Override
    public short index() {
        return index;
    }

    @Override
    public short infoLength() {
        return INFO_LENGTH;
    }

    @Override
    public String toFullString(ConstantPoolInfo[] poolInfos) {
        return "#"+index +" = Class" + "\t\t#"+nameIndex + "\t\t// "+poolInfos[nameIndex].toString(poolInfos);
    }

    @Override
    public String toString(ConstantPoolInfo[] poolInfos) {
        return poolInfos[nameIndex].toString(poolInfos);
    }
}
